package yangan.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import yangan.entity.YanganDataReport;
import yangan.faultHandler.YanganFaultHandler;
import yangan.modle.codecModel.YanganCycleReport;
import yangan.modle.codecModel.YanganEventReport;
import yangan.modle.revModle.RevYanganCycleData;
import yangan.modle.revModle.RevYanganEventData;
import yangan.service.IYanganDataReportService;
import yangan.service.IYanganService;
import yangan.utils.YanganDataDecode;
import yangan.utils.YanganExplain;

@Service("YanganService")
public class YanganServiceImpl implements IYanganService {

    @Autowired
    @Qualifier("YanganDataReportService")
    IYanganDataReportService svcYanganDataReport;

    @Autowired
    YanganFaultHandler yanganFaultHandler;

    @Override
    public boolean saveEventReportData(RevYanganEventData revEventData, String devID) {
        YanganEventReport yanganEventReport= YanganDataDecode.yanganEventDataDecode(revEventData);
        YanganDataReport yanganDataReport= YanganExplain.explainYanganEvent(yanganEventReport);
        yanganDataReport.setInternetDeviceId(devID);
        yanganFaultHandler.eventHandler(yanganDataReport);
        return svcYanganDataReport.save(yanganDataReport);
    }

    @Override
    public boolean saveCycleReportData(RevYanganCycleData revCycleData, String devID) {
        YanganCycleReport yanganCycleReport= YanganDataDecode.yanganCycleDataDecode(revCycleData);
        YanganDataReport yanganDataReport= YanganExplain.explainYanganCycle(yanganCycleReport);
        yanganDataReport.setInternetDeviceId(devID);
        yanganFaultHandler.cycleHandler(yanganDataReport);
        return svcYanganDataReport.save(yanganDataReport);
    }
}
